package controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import util.Game;

import java.util.Collections;

/**
 * 随机产生游戏数据，
 * 对game对象list数据进行洗牌操作，
 * 更新视图
 */
@Controller
@RequestMapping("")
public class StartGameController {
    private Game game = Game.getInstance();

    @RequestMapping("start")
    ModelAndView startGame() {
        ModelAndView mav = new ModelAndView();

        Collections.shuffle(game.getDigits());

        mav.addObject("a", game.getDigitAt(0));
        mav.addObject("b", game.getDigitAt(1));
        mav.addObject("c", game.getDigitAt(2));
        mav.addObject("d", game.getDigitAt(3));
        mav.setViewName("index");
        mav.addObject("status", "start" + game.getDigits().toString());
        ;
        return mav;


    }
}
